package com.xmg.day04;

import java.util.concurrent.*;

/**
 * @Author: mazhongqing
 * @Date: 2020/10/22 17:23
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                TimeUnit.SECONDS.sleep(5);
                return "hello world";
            }
        };
        ExecutorService service = Executors.newCachedThreadPool();
        Future<String> future = service.submit(callable);

        System.out.println(future.get());

        service.shutdown();
    }
}
